import {
	useUserStore
} from '@/stores/user'
import { POST } from '@/server/index'
import {
	LoginParam,
	UserParam,
	PagingParam,
	BookMallListParam,
	GETBookshelfStatusParam,
	SetBookshelfStatusParam,
	GetContentsParam,
	GetRechargeListParam,
	PayBookCurrencyParam,
	PayBookChapterParam,
	GetBookshelfListParam,
	DelBookshelfParam,
	DelRecordsParam,
	AddProposalParam,
	NovelLoveParam,
	itemOrderIdParam,
	GetMapsParam,
	getmpurlParam,
	gettxtrackParam
} from '@/types/api'

let loginUrl = '/Kuaishou/login'

// #ifdef MP-WEIXIN
// 微信
loginUrl = '/login/login'
// #endif

// #ifdef MP-TOUTIAO
// 抖音
loginUrl = '/Tiktok/login'
// #endif

/**
 * 登录
 */
export const login = (data : LoginParam) => POST(loginUrl, data)

/**
 * 获取用户信息
 */
export const getUserinfo = () => POST('/user/getUserinfo')

export const getsign = () => POST('/user/sign')

/**
 * 更新用户头像昵称
 */
export const setUserinfo = (data : UserParam) => POST('/login/setWechatUserInfo', data)

let bookUrl = '/novel/ttnovelList'

// #ifdef MP-WEIXIN
// 微信
bookUrl = '/novel/wxnovelList'
// #endif

// #ifdef MP-TOUTIAO
// 抖音
bookUrl = '/novel/ttnovelList'
// #endif
let bookUrl3 = '/novel/newbookList'
/**
 * 获取首页书籍列表
 */
export const bookMallList = (data : BookMallListParam) => POST(bookUrl, data)

export const bookMallList3 = (data : BookMallListParam) => POST(bookUrl3, data)

/**
 * 获取书架状态
 */
export const getBookshelfStatus = (data : GETBookshelfStatusParam) => POST('/novel/wxbookshelfinfo', data)

let bookshelfStatusUrl

// #ifdef MP-WEIXIN
// 微信
bookshelfStatusUrl = '/novel/wxaddttbookshelf'
// #endif

// #ifndef MP-WEIXIN
// 抖音
bookshelfStatusUrl = '/novel/addttbookshelf'
// #endif

/**
 * 修改书架状态
 */
export const setBookshelfStatus = (data : SetBookshelfStatusParam) => POST(bookshelfStatusUrl, data)

/**
 * 获取章节全部列表解锁情况
 */
export const getContents = (data : GetContentsParam) => POST('/NovelDetails/wxchapter_ispay', data)
export const setMap = (data : GetMapsParam) => POST('/User/setmap', data)

let rechargeListUrl

// // #ifdef MP-WEIXIN
// // 微信
// rechargeListUrl = '/recharge/list'
// // #endif

// // #ifndef MP-WEIXIN
// // 抖音
// rechargeListUrl = '/recharge/ttlist'
// // #endif
rechargeListUrl = '/recharge/wxlist'
/**
 * 获取充值模版
 */
export const getRechargeList = (data : GetRechargeListParam) => POST(rechargeListUrl, data)

let payBookCurrencyUrl
let androidpayBookCurrencyUrl
// #ifdef MP-WEIXIN
// 微信
payBookCurrencyUrl = '/wx/payBookCurrency'
androidpayBookCurrencyUrl = '/wx/androidpayBookCurrency'
// #endif

// #ifdef MP-TOUTIAO
// 抖音
payBookCurrencyUrl = '/tiktok/ttplaceOrder'
// #endif
// #ifdef MP-KUAISHOU
payBookCurrencyUrl = '/kuaishou/placeOrder'
// #endif
/**
 * 微信支付
 */
export const payBookCurrency = (data : PayBookCurrencyParam) => POST(payBookCurrencyUrl, data)
export const androidpayBookCurrency = (data : PayBookCurrencyParam) => POST(androidpayBookCurrencyUrl, data)

/**
 * 书币支付解锁
 */
export const payBookChapter = (data : PayBookChapterParam) => POST('/NovelDetails/wxchapter_findunlock', data)

export const payAll = (data : PayBookChapterParam) => POST('/NovelDetails/chapter_allunlock', data)

// 商品单信息
export const itemOrderId = (data : itemOrderIdParam) => POST('/tiktok/itemOrderId', data)
/**
 * 获取我的书架
 */

export const getBookshelfList = (data : GetBookshelfListParam) => {
	const userStore = useUserStore()
	return POST('/novel/bookshelflist', { app_id: userStore.loginInfo.app_id, ...data })
}
/**
 * 获取推荐书籍列表
 */
export const getBookRecommendedList = (data : PagingParam) => {
	const userStore = useUserStore()
	return POST('/novel/ttrecommendedlist', { app_id: userStore.loginInfo.app_id, ...data })
}

/**
 * 获取阅读记录
 */
export const getRecordsList = () => POST('/novel/wxrecordslist')

export const getRecord = () => POST('/novel/records')

/**
 * 删除书架
 */
export const delBookshelf = (data : DelBookshelfParam) => POST('/novel/deletewxbookshelf', data)

/**
 * 删除浏览记录
 */
export const delRecords = (data : DelRecordsParam) => POST('/novel/deleterecords', data)

/**
 * 充值记录
 */
export const getOrderList = (data : PagingParam) => POST('/user/orderlist', data)

/**
 * 投诉建议
 */
export const addProposal = (data : AddProposalParam) => POST('/novel/proposal', data)

/**
 * 详情页猜你喜欢
 */
export const novelLove = (data : NovelLoveParam) => POST('/Novel/novellove', data)

export const getmpurl = (data : getmpurlParam) => POST('/home/getmpurl', data)
export const txtrack = (data : gettxtrackParam) => POST('/Tx/txtrack', data)